package com.woniuxy.car.commodity.service.starter.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Objects;

/**
 * @Title: CustomMetaObjectHandler
 * @ProjectName: xzhaoo0
 * @Description: TODO
 * @Author: xiong
 * @Date: 2022/2/15 19:25
 */
@Component
public class CustomMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        Object value1 = getFieldValByName("createTime",metaObject);
        if(Objects.isNull(value1)){
            this.setFieldValByName("createTime", LocalDateTime.now(),metaObject);
        }
        Object value2 = getFieldValByName("updateTime",metaObject);
        if(Objects.isNull(value2)){
            this.setFieldValByName("updateTime", LocalDateTime.now(),metaObject);
        }
    }
    @Override
    public void updateFill(MetaObject metaObject) {
        Object value = getFieldValByName("updateTime",metaObject);
        if(Objects.isNull(value)){
            this.setFieldValByName("updateTime", LocalDateTime.now(),metaObject);
        }
    }
}
